package com.baozhun.mall.common.model.bean

import com.baozhun.mall.common.model.enums.OrderStatus
import com.baozhun.mall.common.model.enums.RefundStatus
import java.io.Serializable

/**
 * @Title：订单详情model
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/20
 * @Version：1.0.0
 */
class OrderDetailBean(
    var order_no: String? = "",
    var after_sale_no: String? = "",
    var pay_expire_time: Long = 0,
    var finish_expire_time: Long = 0, //等待买家收货倒计时
    var customer_name: String? = "",
    var customer_phone: String? = "",
    var customer_province: String? = "",
    var customer_city: String? = "",
    var customer_county: String? = "",
    var customer_address: String? = "",
    var total_amount: String = "",
    var pay_amount: String = "",
    var freight: String = "",
    var points: String? = "",//获得的余额
    var points_deduction_amount: String?,//余额抵扣金额
    var order_status: Int = 0,
    var created_at: String = "",
    //商品信息
    var price: String = "",
    var num: String = "",
    var goods_id: String = "",
    var goods_name: String = "",
    var goods_cover: String = "",
    var goods_spec_info: String = "",
    var order_status_name: String? = "",
    var contract_period: String = "", //合约期
    var return_points: String = "", //承诺月消费
    var pay_time: String? = "", //支付时间
    var transaction_id: String? = "", //支付流水号
    var after_sale_enable: Int? = null, //是否可售后，0不能退，1能退
    var after_sale_status: Int? = null,
    var delivery_time: String? = "", //发货时间
    var finish_time: String? = "", //成交时间
    var channel_name: String? = "", //渠道
    var channel_icon: String? = "", //渠道图片
    var rebate_amount: String? = "", //返利金额
    //todo 待核对
    var order_status_desc_detail: String? = "", //订单状态说明详细:您的订单已取消

) : Serializable {

    /**
     * 获取售后状态描述
     */
    fun getRefundDesc(): String? {
        return if (after_sale_enable == 1 || (order_status == OrderStatus.FINISH.status && after_sale_enable == 0)) {
            RefundStatus.APPLY_REFUND.desc
        } else {
            when (after_sale_status) {
                RefundStatus.FINISH.status -> {
                    RefundStatus.FINISH.desc
                }

                else -> {
                    RefundStatus.REFUNDING.desc
                }
            }
        }
    }

    /**
     * 是否显示售后按钮
     *
     */
    fun showRefundBt(): Boolean? {
        return (after_sale_enable == 1) || (order_status == OrderStatus.FINISH.status && after_sale_enable == 0)
    }

    fun buyNumFormat(): String {
        return "x$num"
    }

    /**
     * 是否能退款
     */
    fun enableRefund(): Boolean {
        return after_sale_enable == 1
    }

    /**
     * 是否已经超过退款时间限制
     */
    fun isExceedRefundTimeLimit(): Boolean {
        return order_status == OrderStatus.FINISH.status && after_sale_enable == 0
    }

    fun getNameAndPhone(): String {
        return "$customer_name $customer_phone"
    }

    fun getDetailAddress(): String {
        return customer_province + customer_city + customer_county + customer_address
    }

    /**
     * 是否显示余额抵扣信息
     */
    fun showPointsDeduction(): Boolean {
        return points_deduction_amount != null && points_deduction_amount != "0.00" && points_deduction_amount != "0" && points_deduction_amount != ""
    }

    /**
     * 是否显示余额信息(未支付或者已经获取商城积分的情况下显示)
     */
    fun showBalanceInfo(): Boolean {
        return (order_status == OrderStatus.WAIT_DELIVERY.status) || (points != null && points != "0.00" && points != "0")
    }
}